package com.lzk.worktext.controller;
import java.util.Objects;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzk.worktext.VO.loginVO;
import com.lzk.worktext.common.R;
import com.lzk.worktext.enetity.Employee;
import com.lzk.worktext.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @PostMapping("/employee/login")
    public R<Employee> login(@RequestBody loginVO loginVO) {
        log.info("员工登录,用户名:{}", loginVO.getUsername());
        //构建查询条件
        LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(Employee::getUsername, loginVO.getUsername());
        queryWrapper.eq(Employee::getPassword, DigestUtils.md5DigestAsHex(loginVO.getPassword().getBytes()));
        Employee employee = employeeService.getOne(queryWrapper);
        if (employee == null) {
            return R.error("您的密码错误请重试");
        }
        return R.success(employee);

    }
//    @GetMapping("/page")
//    public R<Page<Employee>>page(String name,int page,int pageSize){
//
//    log.info("页码:{},页码条数,员工姓名:{}",page,pageSize,name);
//    /**创建分页对象**/
//    employeeService.page()
//
//    }












}